﻿/*
 Copyright (c) 2006 - 2008  Eric J. Feminella  <eric@ericfeminella.com>
 All rights reserved.

 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
 in the Software without restriction, including without limitation the rights
 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the Software is 
 furnished to do so, subject to the following conditions:

 The above copyright notice and this permission notice shall be included in 
 all copies or substantial portions of the Software.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 
 THE SOFTWARE.

 @internal
 */

package com.ericfeminella.utils{
	//import com.ericfeminella.exceptions.StaticClassInstantiationException;
	import flash.utils.getDefinitionByName;

	/**
	     * 
	     * Provides a mechanism which enforces a class of static type is 
	     * never instantiated.
	     * 
	     * <p>
	     * All static classes (classes which ONLY contain static members)
	     * are to extend <code>AbstractStaticType</code> in order to ensure
	     * instances can never be instantiated.
	     * </p>
	     * 
	     * <p>
	     * By extending <code>AbstractStaticType</code> it is implied that a 
	     * class instance can not be instantiated.
	     * </p>
	     * 
	     * <p>
	     * Typically Helper, Utility and Enumeration classes will extend
	     * AbstractStaticType to ensure clients do not misuse an API by
	     * attempting to instantiate an instance of the static type
	     * </p>
	     * 
	     * @example
	     * 
	     * <listing version="3.0">
	     * 
	     * package com.ericfeminella.utils
	     * {
	     *     public final class CalculationUtils extends AbstractStaticType
	     *     { 
	     *         public static function calculateX() : String {
	     *             // implementation...
	     *         }
	     *         public static function calculateY() : String {
	     *             // implementation...
	     *         }
	     *     }
	     * }
	     * 
	     * // Attempt to instantiate instance of CalculationUtils
	     * 
	     * var util:CalculationUtils = new CalculationUtils();
	     * 
	     * // results in the following exception being throw
	     * // Illegal instantiation of static type 'com.ericfeminella.utils.CalculationUtils'
	     * 
	     * </listing>
	     * 
	     */
	public class AbstractStaticType {
		/**
		         *
		         * <code>AbstractStaticType</code> constructor determines the sub 
		         * class which was instantiated and throws an error specifying the 
		         * static class which was instantiated.
		         *
		         */
		public function AbstractStaticType() {
			var ClassObject:Class=null;

			var exception:Error=new Error  ;

			if (exception.getStackTrace()!=null) {
				var stackFrame:String=exception.getStackTrace().split("at ")[2];
				var fullyQualifiedName:String=stackFrame.split("()")[0];

				ClassObject=getDefinitionByName(fullyQualifiedName) as Class;
			}

			//throw new StaticClassInstantiationException( ClassObject );    
		}
	}
}